//
//  FCCMessageModels.swift
//  chatUIDemo
//
//  Created by admin on 2025/7/10.
//

import UIKit
import Foundation

// MARK: - 消息状态枚举
enum FCCMessageStatus {
    case qfcSending    // 发送中
    case qfcSent       // 发送成功
    case qfcFailed     // 发送失败
}

// MARK: - 消息类型枚举
enum FCCMessageType {
    case qfcText       // 文本消息
    case qfcImage      // 图片消息
    case qfcAudio      // 语音消息
}

// MARK: - 消息基类
class FCCMessage {
    var qfcId: String
    var qfcSenderId: String
    var qfcSenderAvatarUrl: String
    var qfcIsOutgoing: Bool
    var qfcTimestamp: Date
    var qfcStatus: FCCMessageStatus
    var qfcType: FCCMessageType
    
    init(qfcId: String = UUID().uuidString,
         qfcSenderId: String,
         qfcSenderAvatarUrl: String = "",
         qfcIsOutgoing: Bool,
         qfcTimestamp: Date = Date(),
         qfcStatus: FCCMessageStatus = .qfcSending,
         qfcType: FCCMessageType) {
        self.qfcId = qfcId
        self.qfcSenderId = qfcSenderId
        self.qfcSenderAvatarUrl = qfcSenderAvatarUrl
        self.qfcIsOutgoing = qfcIsOutgoing
        self.qfcTimestamp = qfcTimestamp
        self.qfcStatus = qfcStatus
        self.qfcType = qfcType
    }
}

// MARK: - 文本消息
class FCCTextMessage: FCCMessage {
    var qfcContent: String
    
    init(qfcContent: String,
         qfcSenderId: String,
         qfcSenderAvatarUrl: String = "",
         qfcIsOutgoing: Bool,
         qfcTimestamp: Date = Date(),
         qfcStatus: FCCMessageStatus = .qfcSending) {
        self.qfcContent = qfcContent
        super.init(qfcSenderId: qfcSenderId,
                  qfcSenderAvatarUrl: qfcSenderAvatarUrl,
                  qfcIsOutgoing: qfcIsOutgoing,
                  qfcTimestamp: qfcTimestamp,
                  qfcStatus: qfcStatus,
                  qfcType: .qfcText)
    }
}

// MARK: - 图片消息
class FCCImageMessage: FCCMessage {
    var qfcImageUrl: String?
    var qfcImage: UIImage?
    var qfcImageSize: CGSize
    
    init(qfcImageUrl: String? = nil,
         qfcImage: UIImage? = nil,
         qfcImageSize: CGSize = CGSize(width: 200, height: 200),
         qfcSenderId: String,
         qfcSenderAvatarUrl: String = "",
         qfcIsOutgoing: Bool,
         qfcTimestamp: Date = Date(),
         qfcStatus: FCCMessageStatus = .qfcSending) {
        self.qfcImageUrl = qfcImageUrl
        self.qfcImage = qfcImage
        self.qfcImageSize = qfcImageSize
        super.init(qfcSenderId: qfcSenderId,
                  qfcSenderAvatarUrl: qfcSenderAvatarUrl,
                  qfcIsOutgoing: qfcIsOutgoing,
                  qfcTimestamp: qfcTimestamp,
                  qfcStatus: qfcStatus,
                  qfcType: .qfcImage)
    }
}

// MARK: - 语音消息
class FCCAudioMessage: FCCMessage {
    var qfcAudioUrl: String?
    var qfcDuration: Int // 秒
    var qfcIsPlaying: Bool = false
    
    init(qfcAudioUrl: String? = nil,
         qfcDuration: Int,
         qfcSenderId: String,
         qfcSenderAvatarUrl: String = "",
         qfcIsOutgoing: Bool,
         qfcTimestamp: Date = Date(),
         qfcStatus: FCCMessageStatus = .qfcSending) {
        self.qfcAudioUrl = qfcAudioUrl
        self.qfcDuration = qfcDuration
        super.init(qfcSenderId: qfcSenderId,
                  qfcSenderAvatarUrl: qfcSenderAvatarUrl,
                  qfcIsOutgoing: qfcIsOutgoing,
                  qfcTimestamp: qfcTimestamp,
                  qfcStatus: qfcStatus,
                  qfcType: .qfcAudio)
    }
}